/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = __msmq_analysis_xml.c                              */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/11 by jikw                                 */
/*******************************************************************/
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frct_comm.h"
#include "../../../src/module/msmq/config.h"
#include "../test_msmq_comm.h"
#include <apmtest_comm.h>
#include <frreport_opt.h>
#include <msmq/msmq_core.h>

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

extern int __msmq_analysis_xml(Frreport_body_data *p_st_body_data
                                , Frbyte_Packet *p_st_data
                                , char *p_report_pre
                                , char *p_activex_type);

static void case1(void)
{
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    int i_ret = 0;
    char *p_out = NULL;
    unsigned int ui_out_len = 0;
    FILE *fp_file = NULL;

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    fp_file = fopen("__msmq_analysis_xml1.txt", "rb");
    fseek(fp_file, 0, SEEK_END);
    ui_out_len = ftell(fp_file);
    rewind(fp_file);

    p_out = (char *)frmalloc(ui_out_len);

    fread(p_out, 1, ui_out_len, fp_file);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_out, ui_out_len);


    i_ret = __msmq_analysis_xml(p_st_body_data, p_st_data, (char *)"request.msmq", (char *)"0x03");


    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    fclose(fp_file);
    frfree(p_out);
    bytebuff_free(&p_st_data);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);
    return;

}
/*
static void case2(void)
{
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    int i_ret = 0;
    char *p_out = NULL;
    unsigned int ui_out_len = 0;
    FILE *fp_file = NULL;

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    fp_file = fopen("__msmq_analysis_xml2.txt", "rb");
    fseek(fp_file, 0, SEEK_END);
    ui_out_len = ftell(fp_file);
    rewind(fp_file);

    p_out = (char *)frmalloc(ui_out_len);

    fread(p_out, 1, ui_out_len, fp_file);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_out, ui_out_len);


    i_ret = __msmq_analysis_xml(p_st_body_data, p_st_data, (char *)"request.msmq", (char *)"0x03");


    CU_ASSERT_EQUAL(i_ret, FR_SUCC);

    fclose(fp_file);
    frfree(p_out);
    bytebuff_free(&p_st_data);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);
    return;

}


static void case3(void)
{
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    int i_ret = 0;
    char *p_out = NULL;
    unsigned int ui_out_len = 0;
    FILE *fp_file = NULL;

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    fp_file = fopen("__msmq_analysis_xml3.txt", "rb");
    fseek(fp_file, 0, SEEK_END);
    ui_out_len = ftell(fp_file);
    rewind(fp_file);

    p_out = (char *)frmalloc(ui_out_len);

    fread(p_out, 1, ui_out_len, fp_file);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_out, ui_out_len);


    i_ret = __msmq_analysis_xml(p_st_body_data, p_st_data, (char *)"request.msmq", (char *)"0x03");


    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    fclose(fp_file);
    frfree(p_out);
    bytebuff_free(&p_st_data);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);
    return;

}


static void case4(void)
{
    Frbyte_Packet *p_st_data = NULL;
    Frreport_body_data *p_st_body_data = NULL;
    Conntrack *p_st_conn = NULL;

    int i_ret = 0;
    char *p_out = NULL;
    unsigned int ui_out_len = 0;
    FILE *fp_file = NULL;

    p_st_conn = (Conntrack *)frmalloc(sizeof(Conntrack));
    memset(p_st_conn, 0x00, sizeof(Conntrack));

    p_st_conn->flg_direct_known = FR_DIRECT_KNOWN;
    p_st_conn->st_l7_analyzer.p_st_l7_module = (L7_module *)"1";

    p_st_body_data = frreport_body_new_l7(p_st_conn);

    fp_file = fopen("__msmq_analysis_xml4.txt", "rb");
    fseek(fp_file, 0, SEEK_END);
    ui_out_len = ftell(fp_file);
    rewind(fp_file);

    p_out = (char *)frmalloc(ui_out_len);

    fread(p_out, 1, ui_out_len, fp_file);

    //测试修改部分
    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, p_out, ui_out_len);


    i_ret = __msmq_analysis_xml(p_st_body_data, p_st_data, (char *)"request.msmq", (char *)"0x03");


    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    fclose(fp_file);
    frfree(p_out);
    bytebuff_free(&p_st_data);
    frfree(p_st_conn);
    frreport_body_free(&p_st_body_data);
    return;

}
*/
int add_suite__msmq_analysis_xml(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __msmq_analysis_xml()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
